package com.fire8.dolphin.utils;

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;

/**
 * 
 * @ClassName: DateUtil
 * @Description: 日期处理工具.
 * @author timwang
 * @date 2010-4-23 下午03:45:05
 *
 */
public class DateUtil
{
    
    /**
     * 年格式化字串
     */
    public static final String DATE_FORMAT = "yyyy-MM-dd";
    
    /**
     * 时分秒格式化字串
     */
    public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    
    /**
     * 获取星期字符串。例如："Sunday"、"Monday" 等等 
     * 星期字符串。使用 Calendar.SUNDAY、Calendar.MONDAY 等指出所得数组。

     */
    public static final String[] weekdays = new DateFormatSymbols().getWeekdays();
    
    public static final HashMap<Integer,String> dayOfWeekMap = new HashMap<Integer, String>(); 
    
    static{
        dayOfWeekMap.put(Calendar.SUNDAY, "日");
        dayOfWeekMap.put(Calendar.MONDAY, "一");
        dayOfWeekMap.put(Calendar.TUESDAY, "二");
        dayOfWeekMap.put(Calendar.WEDNESDAY, "三");
        dayOfWeekMap.put(Calendar.THURSDAY, "四");
        dayOfWeekMap.put(Calendar.FRIDAY, "五");
        dayOfWeekMap.put(Calendar.SATURDAY, "六");
    }
    
    /**
     * 将String型格式化,比如想要将2011-11-11格式化成2011年11月11日,就StringPattern("2011-11-11","yyyy-MM-dd","yyyy年MM月dd日"). 
     * <功能详细描述>
     * @param date 想要格式化的日期  
     * @param oldPattern 想要格式化的日期的现有格式  
     * @param newPattern 想要格式化成什么格式  
     * @return [参数说明]
     *
     * @author wangchd
     * @see [类、类#方法、类#成员]
     */
    public final static String StringPattern(String date, String oldPattern, String newPattern) {    
        if (date == null || oldPattern == null || newPattern == null)    
            return "";    
        SimpleDateFormat sdf1 = new SimpleDateFormat(oldPattern) ;        // 实例化模板对象     
        SimpleDateFormat sdf2 = new SimpleDateFormat(newPattern) ;        // 实例化模板对象     
        Date d = null ;     
        try{     
            d = sdf1.parse(date) ;   // 将给定的字符串中的日期提取出来     
        }catch(Exception e){            // 如果提供的字符串格式有错误，则进行异常处理     
            e.printStackTrace() ;       // 打印异常信息     
       }     
        return sdf2.format(d);   
    }  
    
    /**
     * 获取当前时间
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String 
     */
    public static String getDayTime(String format)
    {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setLenient(false);
        String datetime = sdf.format(calender.getTime());
        return datetime;
    }
    
    /**
     * 将日期转换成指定格式
     * <功能详细描述>
     * @param date
     * @return 格式化后的日期
     *
     * @author lxg
     * @throws ParseException 
     * @see [类、类#方法、类#成员]
     */
    public static Date getDateFormat(Date date) throws ParseException
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
        return dateFormat.parse(dateFormat.format(date));
    }
    /**
     * 将日期转换成指定格式
     * <功能详细描述>
     * @param date
     * @return 格式化后的日期
     *
     * @author lxg
     * @throws ParseException 
     * @see [类、类#方法、类#成员]
     */
    public static Date getDateFormat(Date date,String format) throws ParseException
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.parse(dateFormat.format(date));
    }
    
    /**
     * 获取当前时间
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String 
     * 格式:yyyy-MM-dd HH:mm:ss
     */
    public static String getDayTime()
    {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setLenient(false);
        String datetime = format.format(calender.getTime());
        return datetime;
    }
    
    /**
     * 获取当前日期
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String 
     * 格式:yyyy-MM-dd
     */
    public static String getDayDate()
    {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);
        String datetime = format.format(calender.getTime());
        return datetime;
    }
    
    /**
     * 将日期Date 型的日期转化为String 型
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String 
     * 格式:yyyy-MM-dd
     */
    public static String getDayDate(Date date)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);
        String datetime = format.format(date);
        return datetime;
    }
    
    /**
     * 将日期Date 型的日期转化为String 型
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String 
     * 格式:yyyy-MM-dd
     */
    public static String getDayDateFormat(Date date)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy 年 MM 月 dd 日");
        format.setLenient(false);
        String datetime = format.format(date);
        return datetime;
    }
    
    /**
     * 取得当前日期与星期数
     * <功能详细描述>
     * @return [参数说明]
     *
     * @author 王成达
     * @throws ParseException 
     * @see [类、类#方法、类#成员]
     */
    public static String getDayAndWeek() throws ParseException
    {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);
        String datetime = format.format(calender.getTime());
        calender.setTime(calender.getTime());
        datetime = datetime + " "
                + weekdays[calender.get(Calendar.DAY_OF_WEEK)];//取得星期数
        return datetime;
    }
    
    public static String getDateToStringFormat(Date date)
    {
        SimpleDateFormat format = new SimpleDateFormat(TIME_FORMAT);
        format.setLenient(false);
        String datetime = format.format(date);
        return datetime;
    }
    
    public static Date getTimeFormat(Date date) throws ParseException
    {
        SimpleDateFormat format = new SimpleDateFormat(TIME_FORMAT);
        format.setLenient(false);
        String datetime = format.format(date);
        Date dateTime2 = format.parse(datetime);
        return dateTime2;
    }
    
    /**
     * 将日期转换成字符串
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String
     */
    public static String dateToStr(Date date, String format)
    {
        if (date == null)
        {
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format); // HH一定要大写，小写的话，变成12小时日期制
        sdf.setLenient(false);
        String datetime = sdf.format(date);
        return datetime;
    }
    
    /**
     * 取得当前日期(yyyy-MM-dd)
     * @return Date
     * @throws ParseException 
     */
    public static Date getNowDate() throws ParseException
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = formatter.parse(getDayTime());
        return date;
    }
    
    /**
     * 取得当前日期(yyyy-MM-dd HH:mm:ss)
     * @return Date
     * @throws ParseException 
     */
    public static Date getNowDateTime() throws ParseException
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dateTime = formatter.parse(getDayTime());
        return dateTime;
    }
    
    /**
     * 取得当前日期
     * format: yyyy-MM-dd HH:mm:ss
     * @return Date
     */
    public static Date getNowDate(String formate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat(formate);
        java.util.Date currentTime_1 = new java.util.Date();
        String dateString = formatter.format(currentTime_1);
        ParsePosition pos = new ParsePosition(8);
        Date currentTime_2 = formatter.parse(dateString, pos);
        return currentTime_1;
    }
    
    /**
     * 将字符串转化为日期
     * str 为空时返回当前日期
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return Date
     * 格式:yyyy-MM-dd
     * @throws ParseException 
     */
    public static Date strToDate(String str)
    {
        return strToDate(str,DATE_FORMAT);
    }
    
    /**
     * 将字符串转化为日期
     * str 为空时返回当前日期
     * HH一定要大写，小写的话，变成12小时日期制
     * format: yyyy-MM-dd HH:mm:ss
     * @return String
     */
    public static Date strToDate(String str, String format)
    {
        Date datetime = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format); // HH一定要大写，小写的话，变成12小时日期制
        sdf.setLenient(false);
        if (StringUtil.isEmpty(str))
        {
            return new Date();
        }
        try
        {
            datetime = sdf.parse(str);
        }
        catch (Exception e)
        {
            return new Date();
        }
        return datetime;
    }
    
    /**
     * 取得已当前时间差几天的时间
     * @param timeType 1,2,3,5
     * @param difference
     * @return yyyy-MM-dd
     *  gc.add(1,-1)表示年份减一.
     *	gc.add(2,-1)表示月份减一.
     *	gc.add(3.-1)表示周减一.
     *	gc.add(5,-1)表示天减一.
     */
    public static String getDifferenceNowDate(int timeType, int difference)
    {
        return getDifferenceNowDate(timeType,difference,TIME_FORMAT);
    }
    
    /**
     * 取得已当前时间差几天的时间
     * @param timeType 1,2,3,5
     * @param difference
     * @return yyyy-MM-dd
     *  gc.add(1,-1)表示年份减一.
     *  gc.add(2,-1)表示月份减一.
     *  gc.add(3.-1)表示周减一.
     *  gc.add(5,-1)表示天减一.
     */
    public static String getDifferenceNowDate(int timeType, int difference,String format)
    {
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat(format);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(timeType, difference);
        gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE));
        return df.format(gc.getTime());
    }
    
    /**
     * 取得已当前时间差几天的时间
     * @param timeType 1,2,3,5
     * @param difference
     * @return yyyy-MM-dd
     *  gc.add(1,-1)表示年份减一.
     *	gc.add(2,-1)表示月份减一.
     *	gc.add(3.-1)表示周减一.
     *	gc.add(5,-1)表示天减一.
     *  @return  Date
     */
    public static Date getDiffDate(int timeType, int difference)
    {
        Date date = new Date();
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.add(timeType, difference);
        gc.set(gc.get(gc.YEAR),
                gc.get(gc.MONTH),
                gc.get(gc.DATE),
                gc.get(gc.HOUR_OF_DAY),
                gc.get(gc.MINUTE),
                gc.get(gc.SECOND));
        return gc.getTime();
    }
    
    public static String getDay(String date)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date beginDate = null;
        java.util.Date endDate = null;
        try
        {
            beginDate = format.parse(date);
            endDate = format.parse(getDayDate());
        }
        catch (ParseException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        long day = (endDate.getTime() - beginDate.getTime())
                / (24 * 60 * 60 * 1000);
        //System.out.println("相隔的天数="+day); 
        if (day == 0)
        {
            return "0";
        }
        return String.valueOf(day);
    }
    
    /**
     * 取得格式化后的时间，如:一小时前， 一天前，两天前，
     * @param dateTime
     * @return
     * @throws ParseException 
    
    public static String getFormatDate(Date dateTime) throws ParseException{
    	String 	formaStr = "";
    	Date nowDate = getNowDateTime();
    	nowDate.getTime();
    	Calendar bCal = Calendar.getInstance();
    	bCal.setTime(dateTime);
    	Calendar nowCal = Calendar.getInstance();
    	nowCal.setTime(nowDate);
    	Long bl = bCal.getTimeInMillis();
    	Long nowL = nowCal.getTimeInMillis();
    	
    	int yDif = nowCal.get(Calendar.YEAR) - bCal.get(Calendar.YEAR) ;
    	int monDif = nowCal.get(Calendar.MONTH)- bCal.get(Calendar.MONTH);
    	int dDif = nowCal.get(Calendar.DAY_OF_YEAR) - bCal.get(Calendar.DAY_OF_YEAR);
    	int hDif = nowCal.get(Calendar.HOUR_OF_DAY) - bCal.get(Calendar.HOUR_OF_DAY);
    	int minDif = nowCal.get(Calendar.MINUTE) - bCal.get(Calendar.MINUTE);
    	int secDif = nowCal.get(Calendar.SECOND) - bCal.get(Calendar.SECOND);
    	if(yDif > 1){ //>= 2 年的 按 年算
    		formaStr = yDif + "年前";
    	}else{ // >1 年的 && 在12 个月之内的按 月算
    		
    	}
    	if((yDif == 0)&&(monDif == 0)&&(dDif > 0)){//本月 
    		formaStr = dDif + "天前" ;
    	}
    	else if((yDif == 0)&&(monDif > 0)&&(dDif > 20)){//前月 且 < 20 天的，按天计算
    		formaStr =  monDif + "个月前";
    	}else if((yDif == 0)&&(monDif > 0)&&(dDif <= 20)){////前月 且 > 20 天的，按月
    		formaStr = + dDif + "天前";
    	}else if((yDif == 0)&&(monDif == 0)&&(dDif == 0)&&(hDif > 0)){// 同年，同月，同天，不等小时
    		formaStr =  hDif + "小时前";
    	}else if((yDif == 0)&&(monDif == 0)&&(dDif == 0)&&(hDif == 0)&&(minDif > 0)){// 同年，同月，同天，不等小时
    		formaStr = minDif + "分钟前";
    	}else if((yDif == 0)&&(monDif == 0)&&(dDif == 0)&&(hDif == 0)&&(minDif == 0)){// 同年，同月，同天，不等小时
    		formaStr =  1 + "分钟前";
    	}
    	return formaStr;
    } */
    
    /**
     * 取得格式化后的时间，如:一小时前， 一天前，两天前，
     * @param dateTime
     * @return
     * @throws ParseException 
     */
    public static String getFormatDate(Date dateTime) throws ParseException
    {
        String formaStr = "";
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date now = dfs.parse(dfs.format(DateUtil.getNowDateTime()));
        java.util.Date temp = dfs.parse(dfs.format(dateTime));
        long between = (now.getTime() - temp.getTime()) / 1000;//除以1000是为了转换成秒 
        
        long dayDiff = between / (24 * 3600);
        long monthDiff = between / (24 * 3600 * 30);
        long hourDiff = between % (24 * 3600) / 3600;
        long minuteDiff = between % 3600 / 60;
        //long secondDiff = between%60/60;
        long yearDiff = between / (24 * 3600 * 30 * 10);
        if ((dayDiff == 0) && (monthDiff == 0) && (hourDiff == 0)
                && (minuteDiff == 0) && (between != 0))
        {
            formaStr = String.valueOf(minuteDiff) + "秒钟前";
        }
        else if ((dayDiff == 0) && (monthDiff == 0) && (hourDiff == 0)
                && (minuteDiff != 0))
        {
            formaStr = String.valueOf(minuteDiff) + "分钟前";
        }
        else if ((dayDiff == 0) && (monthDiff == 0) && (hourDiff != 0))
        {
            formaStr = String.valueOf(hourDiff) + "小时前";
        }
        else if ((dayDiff != 0) && (monthDiff != 0) && (monthDiff < 12))
        {
            formaStr = String.valueOf(monthDiff) + "个月前";
        }
        else if ((monthDiff == 0) && (dayDiff != 0))
        {
            formaStr = String.valueOf(dayDiff) + "天前";
        }
        else if (monthDiff >= 12)
        {
            formaStr = String.valueOf(yearDiff) + "年前";
        }
        else
        {
            formaStr = "当前";
        }
        return formaStr;
    }
    
    /**
     * 是否在当前时间之后.
     * @param date
     * @return
     * @throws ParseException
     */
    public static boolean isAffterNowDate(Date date) throws ParseException
    {
        if (date == null)
        {//传入空值
            return true;
        }
        Date nowDate = getNowDate();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date dd = formatter.parse(formatter.format(date));
        return dd.after(nowDate);
    }
    
    /**
     * 取得当前年，格式：yyyy
     * @return
     */
    public static String getNowYear()
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        format.setLenient(false);
        String datetime = format.format(getNowDate("yyyy"));
        return datetime;
    }
    
    /**
     * 取得当前年.格式：yy
     * @return
     */
    public static String getNowYearYY()
    {
        SimpleDateFormat format = new SimpleDateFormat("yy");
        format.setLenient(false);
        String datetime = format.format(getNowDate("yy"));
        return datetime;
    }
    
    /**
     * 取得当前月.
     * @return
     */
    public static String getNowMonth()
    {
        SimpleDateFormat format = new SimpleDateFormat("MM");
        format.setLenient(false);
        String datetime = format.format(getNowDate("MM"));
        return datetime;
    }
    
    /**
     * 取得当前天.
     * @return
     */
    public static String getNowDay()
    {
        SimpleDateFormat format = new SimpleDateFormat("dd");
        format.setLenient(false);
        String datetime = format.format(getNowDate("dd"));
        return datetime;
    }
    
    /**
     * 取得当前季度.
     * @return
     */
    public static String getNowQ()
    {
        SimpleDateFormat format = new SimpleDateFormat("mm");
        format.setLenient(false);
        String datetime = format.format(getNowDate("mm"));
        int i = Integer.valueOf(datetime);
        String q = "1";
        if (i >= 3 && i <= 5)
            q = "2";
        if (i >= 6 && i <= 8)
            q = "3";
        if (i >= 9 && i <= 11)
            q = "4";
        return q;
    }
    
    /**
     * 获取当前年月的第一天：yyyy-MM-1<br>
     * <功能详细描述>
     * @return [参数说明]
     *
     * @author 许洋
     * @see [类、类#方法、类#成员]
     */
    public static Date getThisYearMonth()
    {
        String strYear = getNowYear();
        String strMonth = getNowMonth();
        String strDate = strYear + "-" + strMonth + "-1";
        
        return strToDate(strDate);
    }
    
    /**
     * 比较日期
     * <功能详细描述>
     * @param date
     * @param date1
     * @return [参数说明]
     *
     * @author 陈锦轮
     * @see [类、类#方法、类#成员]
     */
    public static int getDiffDate(Date date, Date date1)
    {
        return (int)((date.getTime() - date1.getTime()) / (24 * 3600 * 1000));
    }
    
    
    /**
     * 获取指定日期的在当月的号数(当月的第几天)
     * <功能详细描述>
     * @param date 指定的日期
     * @return [参数说明] 当月的第几天
     *
     * @author lxg
     * @see [类、类#方法、类#成员]
     */
    public static int getDayOfMonthByDate(Date date)
    {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(c.DAY_OF_MONTH);
        
    }
    /**
     * 日期累加
     * <功能详细描述>
     * @param date
     * @param offset
     * @return [参数说明]
     *
     * @author 陈锦轮
     * @see [类、类#方法、类#成员]
     */
    public static Date changeDay(Date date, int offset)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_YEAR,
                (calendar.get(Calendar.DAY_OF_YEAR) + offset));
        return calendar.getTime();
    }
    
    /**
     * 返回指定月份的第一天
     * <功能详细描述>
     * @param month
     * @return [参数说明] 指定的月份，从0开始算
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static Date getFirstDayByMonth(int month)
    {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MONTH, month);
        SimpleDateFormat sdf=new SimpleDateFormat(DATE_FORMAT);
        //当前月的第一天  
        cal.set(GregorianCalendar.DAY_OF_MONTH, 1); 
        Date beginTime=cal.getTime();
        String beginTime1=sdf.format(beginTime)+" 00:00:00";
        sdf = new SimpleDateFormat(TIME_FORMAT);
        try
        {
            return sdf.parse(beginTime1);
        }
        catch (ParseException e)
        {
            return null;
        }
    }
    
    /**
     * 返回指定月份的最后一天
     * <功能详细描述>
     * @param month
     * @return [参数说明] 指定的月份，从0开始计算
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static Date getLastDayByMonth(int month)
    {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MONTH, month);
        SimpleDateFormat sdf=new SimpleDateFormat(DATE_FORMAT);
        //当前月的最后一天   
        cal.set( Calendar.DATE, 1 );
        cal.roll(Calendar.DATE, - 1 );
        Date endTime=cal.getTime();
        String endTime1=sdf.format(endTime)+" 23:59:59";
        sdf = new SimpleDateFormat(TIME_FORMAT);
        try
        {
            return sdf.parse(endTime1);
        }
        catch (ParseException e)
        {
            return null;
        }
    }
    
    /**
     * 得到本周周一
     * <功能详细描述>
     * @return [参数说明]
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static Date getMondayOfThisWeek()
    {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
                
        if (dayofweek == 0)
            dayofweek = 7;
        c.add(Calendar.DATE, -dayofweek + 1);
        String tem = getDayDate(c.getTime())+" 00:00:00";
        return strToDate(tem, TIME_FORMAT);
        
    }
    
    /**
      *得到本周周日 
      * @return yyyy-MM-dd
      */
    public static Date getSundayOfThisWeek()
    {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
               
        if (dayofweek == 0)
            dayofweek = 7;
        c.add(Calendar.DATE, -dayofweek + 7);
        String tem = getDayDate(c.getTime())+" 23:59:59";
        return strToDate(tem, TIME_FORMAT);
    }
    
    /**
     * 获取指定日期是星期几
     * <功能详细描述>
     * @param date
     * @return [参数说明]
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static int getDayOfDate(Date date)
    {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_WEEK);
    }
    
    /**
     * 计算指定日期是当年第几周
     * <功能详细描述>
     * @param date
     * @return [参数说明]
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static int getWeekNum(Date date)
    {
        Calendar calender = Calendar.getInstance();
        calender.setTime(date);
        calender.setMinimalDaysInFirstWeek(7);
        calender.setFirstDayOfWeek(Calendar.MONDAY);
        return  calender.get(Calendar.WEEK_OF_YEAR);
    }
    
    /**
     * 计算指定周的星期一
     * <功能详细描述>
     * @param weekNum
     * @return [参数说明]
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static String getMondayByWeekNum(int year,int weekNum)
    {
        Calendar calender = Calendar.getInstance();
        calender.set(Calendar.YEAR, year);
        calender.setMinimalDaysInFirstWeek(7);
        calender.set(calender.WEEK_OF_YEAR, weekNum);
        calender.set(calender.DAY_OF_WEEK, GregorianCalendar.MONDAY);
        return dateToStr(calender.getTime(), DATE_FORMAT);
    }
    /**
     * 计算指定周的星期五
     * <功能详细描述>
     * @param weekNum
     * @return [参数说明]
     *
     * @author 李秀刚
     * @see [类、类#方法、类#成员]
     */
    public static String getFridayByWeekNum(int year,int weekNum)
    {
        Calendar calender = Calendar.getInstance();
        calender.set(Calendar.YEAR, year);
        calender.setMinimalDaysInFirstWeek(7);
        calender.set(calender.WEEK_OF_YEAR, weekNum);
        calender.set(calender.DAY_OF_WEEK, GregorianCalendar.FRIDAY);
        return dateToStr(calender.getTime(), DATE_FORMAT);
    }
    /**
     * @param args
     *            java中对日期的加减操作 gc.add(1,-1)表示年份减一. gc.add(2,-1)表示月份减一.
     *            gc.add(3.-1)表示周减一. gc.add(5,-1)表示天减一.
     * @throws ParseException
     */
    public static void main(String[] args) throws ParseException
    {
        //System.out.println(getThisYearMonth());
        
        //System.out.println(getWeekNum(new Date()));
        /*	String formaStr = "";
        	SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        	java.util.Date now =dfs.parse(dfs.format(DateUtil.getNowDateTime())); 
        	java.util.Date temp = dfs.parse("2008-01-01 09:43:30"); 
        	long between=(now.getTime()-temp.getTime())/1000;//除以1000是为了转换成秒 

        	long dayDiff = between/(24*3600);
        	long monthDiff = between/(24*3600*30);
        	long hourDiff = between%(24*3600)/3600; 
        	long minuteDiff = between%3600/60; 
        	long secondDiff = between%60/60;
        	long yearDiff =  between/(24*3600*30*10);
        	if((dayDiff == 0)&&(monthDiff == 0)&&(hourDiff == 0)&&(minuteDiff == 0)&&(between != 0)){
        		formaStr = String.valueOf(minuteDiff)+"秒钟前";
        	}else if((dayDiff == 0)&&(monthDiff == 0)&&(hourDiff == 0)&&(minuteDiff != 0)){
        		formaStr = String.valueOf(minuteDiff)+"分钟前";
        	}else if((dayDiff == 0)&&(monthDiff == 0)&&(hourDiff != 0)){
        		formaStr = String.valueOf(hourDiff)+"小时前";
        	}else if((dayDiff != 0)&&(monthDiff != 0)&&(monthDiff<12)){
        		formaStr = String.valueOf(monthDiff)+"个月前";
        	}else if((monthDiff == 0)&&(dayDiff != 0)){
        		formaStr = String.valueOf(dayDiff)+"天前";
        	}else if(monthDiff >= 12){
        		formaStr = String.valueOf(yearDiff)+"年前";
        	}else {
        		formaStr = "当前";
        	}
        	
        	System.out.println("day1:"+dayDiff);
        	System.out.println("monthDiff:"+monthDiff);
        	System.out.println("hour1:"+hourDiff);
        	System.out.println("minute1:"+minuteDiff);
        	System.out.println("second1:"+secondDiff);
        	System.out.println("yearDiff:"+yearDiff);*/
        Calendar c = Calendar.getInstance();
        c.set(2012, 0, 2);
        System.out.println(getWeekNum(c.getTime()));
        System.out.println(getMondayByWeekNum(2011,52));
        System.out.println(getFridayByWeekNum(2011,52));
        System.out.println(getMondayByWeekNum(2012,0));
        System.out.println(getFridayByWeekNum(2012,0));
        System.out.println(getMondayByWeekNum(2012,1));
        System.out.println(getFridayByWeekNum(2012,1));
    }
    
}
